package cc.miwuya.property.service.impl;

import cc.miwuya.property.domain.Repair;
import cc.miwuya.property.mapper.RepairMapper;
import cc.miwuya.property.service.RepairService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author 杩烽浘妫灄
 * @description 针对表【repair(报修表)】的数据库操作Service实现
 * @createDate 2024-02-22 19:49:08
 */
@Service
public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair>
        implements RepairService {

    @Override
    public Object getPage(Page page, String name, Long residentialId) {
        Page<Repair> repairPage;
        if (StrUtil.isEmpty(name)) {
            repairPage = page(page, new QueryWrapper<Repair>().eq("residential_id", residentialId));
        } else {
            repairPage = page(page, new QueryWrapper<Repair>().eq("residential_id", residentialId).like("address", name));
        }

        return repairPage;
    }

    @Override
    public Object getOwnerRepairList(Page page, String name, Long residentialId, String userId) {
        Page<Repair> repairPage;
        if (StrUtil.isEmpty(name)) {
            repairPage = page(page, new QueryWrapper<Repair>().eq("residential_id", residentialId).eq("user_id", userId));
        }else {
            repairPage = page(page,new QueryWrapper<Repair>().eq("residential_id", residentialId).like("address", name).eq("user_id", userId));
        }
        return repairPage;
    }
}




